<?php
$link=new mysqli('127.0.0.1','root','root','books_manage_system','3306');
if($link->connect_error){
    die('连接失败'.$link->connect_error);
}else{
    //连接成功，设置编码格式
    mysqli_set_charset($link,'utf8');
    $link->query('SET NAMES UTF8');

    //存储数据
    $result=array();
    $result['data']=array();

    $sql="select * from category where status='1'";
    $re=$link->query($sql);
    $row=mysqli_num_rows($re);
    if($row>0){
        // 遍历数据  存储在$reuslt
        while($rows = $re->fetch_assoc()) {
            $result['status']='success';
            array_push($result['data'],$rows);
        }
    }else{
        $result['status']='fail';
    }
    mysqli_free_result($re); //释放结果集
    //关闭数据库
    $link->close();
    die(json_encode($result));
    }
?>